﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MySixteenthWPFDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (list.SelectedItem == null)
                return;
            this.txtSelction.Text = $"You choose item at position {list.SelectedIndex + 1}\r]nChecked state is {((CheckBox)list.SelectedItem).IsChecked}";
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder str = new StringBuilder();
            foreach(CheckBox item in list.Items)
            {
                if(item.IsChecked == true)
                {
                    str.Append($"{item.Content} is checked\r\n");                   
                }
                txtSelction.Text = str.ToString();
            }
        }
    }
}
